package com.hotcars.dao;

// Generated Mar 10, 2013 6:26:23 PM by Hibernate Tools 3.4.0.CR1

import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.hotcars.model.Car;

/**
 * Home object for domain model class Cars.
 * @see com.hotcars.dao.Cars
 * @author Hibernate Tools
 */
@Stateless
public class CarsHome {

	private static final Log log = LogFactory.getLog(CarsHome.class);

	@PersistenceContext
	private EntityManager entityManager;

	public void persist(Car transientInstance) {
		log.debug("persisting Car instance");
		try {
			entityManager.persist(transientInstance);
			log.debug("persist successful");
		} catch (RuntimeException re) {
			log.error("persist failed", re);
			throw re;
		}
	}

	public void remove(Car persistentInstance) {
		log.debug("removing Car instance");
		try {
			entityManager.remove(persistentInstance);
			log.debug("remove successful");
		} catch (RuntimeException re) {
			log.error("remove failed", re);
			throw re;
		}
	}

	public Car merge(Car detachedInstance) {
		log.debug("merging Car instance");
		try {
			Car result = entityManager.merge(detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	/*public List<Car> findAll() {
		log.debug("getting all Car instances");
		try {
			Car instance = entityManager.find(Car.class, id);
			log.debug("get successful");
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}*/
	
	public Car findById(Integer id) {
		log.debug("getting Car instance with id: " + id);
		try {
			Car instance = entityManager.find(Car.class, id);
			log.debug("get successful");
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}
}
